<%@ page language="java"    import="java.util.*,java.io.*,java.text.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ page import="org.apache.commons.fileupload.*" %>  
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>  
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<%
    PrintWriter pw=response.getWriter();
    String uploadPath= this.getServletContext().getRealPath("/uploads")+
    		"/"+new SimpleDateFormat("yyyy").format(new Date())+"/"
    		+new SimpleDateFormat("MM").format(new Date())+"/"+
    		new SimpleDateFormat("dd").format(new Date())+"/";
    File file=new File(uploadPath);
    if(!file.exists() && !file.isDirectory()){
    	file.mkdirs();
    }
    request.setCharacterEncoding("UTF-8");
    
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if(isMultipart){ 
    	 FileItemFactory factory = new DiskFileItemFactory();  
         ServletFileUpload upload= new ServletFileUpload(factory);
         List<FileItem> items = null;  
         items=upload.parseRequest(request);  
         Iterator<FileItem> iterator = items.iterator(); 
         while(iterator.hasNext()){ 
        	 
        	 FileItem item = iterator.next();  
             //保存上传文件  
             if(item.isFormField()){  
                 //处理普通文本字段  
                 String fieldName = item.getFieldName();  
                 if(fieldName.equals("username")){  
                     out.print(item.getString());  
                 }else if(fieldName.equals("password")){  
                     out.print(item.getString());  
                 }  
             }else{  
                 String fullfile = item.getName();  
                 File uploadfile = new File(uploadPath,fullfile);  
                 item.write(uploadfile);  
             }  
         }
      }
	pw.write("success");
%>
</body>
</html>